package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.SurveyQuiz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface SurveyQuizRepository extends JpaRepository<SurveyQuiz, Long>,JpaSpecificationExecutor<SurveyQuiz> {

    @Query(value = "SELECT  b FROM SurveyQuiz b JOIN b.tags t WHERE  b.isAvailable=true AND t.name in :names")
    List<SurveyQuiz> findQuizzesByTags(@Param("names") List<String> names);

    List<SurveyQuiz> findByIdIn(List<Long> ids);

    List<SurveyQuiz> findAllByIsAvailableIsTrueAndIdIn(List<Long> quizIds);

}
